package pos.utils;

import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;

public class SimpleSSLMail {

	private static final String SMTP_HOST_NAME = "smtp.gmail.com";
	private static final int SMTP_HOST_PORT = 465;
	private static final String SMTP_AUTH_USER = "contactobxip@gmail.com";
	private static final String SMTP_AUTH_PWD = "accmaccm";
	private String correo = "";
	private String texto = "Nueva Oferta";
	private String titulo = "bXip Informa";

	public SimpleSSLMail(String correo, String texto, String titulo) {
		this.correo = correo;
		this.texto = texto;
		this.titulo = titulo;
	}

	public String getCorreo() {
		return correo;
	}

	public void setCorreo(String correo) {
		this.correo = correo;
	}

	public void test() {
		Properties props = new Properties();

		props.put("mail.transport.protocol", "smtps");
		props.put("mail.smtps.host", SMTP_HOST_NAME);
		props.put("mail.smtps.auth", "true");
		// props.put("mail.smtps.quitwait", "false");
		try{
		Session mailSession = Session.getDefaultInstance(props);
		mailSession.setDebug(true);
		
		Transport transport = mailSession.getTransport();

		MimeMessage message = new MimeMessage(mailSession);
		message.setSubject(this.getTitulo());
		message.setContent(this.getTexto(), "text/plain");

		message.addRecipient(Message.RecipientType.TO, new InternetAddress(this
				.getCorreo()));

		transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER,
				SMTP_AUTH_PWD);

		transport.sendMessage(message, message
				.getRecipients(Message.RecipientType.TO));
		transport.close();
		}catch(Exception e){
			System.out.println("Error enviando correo");
		}
	}

	public void setTexto(String texto) {
		this.texto = texto;
	}

	public String getTexto() {
		return texto;
	}

	public void setTitulo(String titulo) {
		this.titulo = titulo;
	}

	public String getTitulo() {
		return titulo;
	}
}